{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np  \n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "import scipy.stats as stats\n",
    "import glob"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get LIONESS, SPCC, and SWEET networks\n",
    "\n",
    "Here we describe how to compute and pre-process the other networks.\n",
    "\n",
    "WARNING: most of these steps are memory and time intensive. We have put all the steps here so it would be easier to\n",
    "find, but realistically you might want to split them in separate files. \n",
    "We would recommend you try them \n",
    "out on a smaller amount of samples before running the whole notebook."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "\n",
    "# LIONESS\n",
    "def lioness_scaled(data, i):\n",
    "    # Construct sample specific network\n",
    "\n",
    "    corr_all = np.corrcoef(data)\n",
    "    v0 = pd.DataFrame.drop(data, i, axis=1)\n",
    "    corr_single = np.corrcoef(v0)\n",
    "    x = data.shape[1] * (corr_all - corr_single) + corr_single\n",
    "    x[np.isnan(x)] = 0\n",
    "\n",
    "    m_x = np.max(np.abs(x[x != 0]))\n",
    "    x = x/m_x\n",
    "    np.fill_diagonal(x, 1)\n",
    "    \n",
    "    corrnet = x\n",
    "\n",
    "    return corrnet\n",
    "  \n",
    "# LIONESS ORIGINAL\n",
    "def lioness(data, i):\n",
    "    # Construct sample specific network\n",
    "\n",
    "    corr_all = np.corrcoef(data)\n",
    "    v0 = pd.DataFrame.drop(data, i, axis=1)\n",
    "    corr_single = np.corrcoef(v0)\n",
    "    x = data.shape[1] * (corr_all - corr_single) + corr_single\n",
    "    x[np.isnan(x)] = 0\n",
    "\n",
    "    #m_x = np.max(np.abs(x[x != 0]))\n",
    "    #x = x/m_x\n",
    "    #np.fill_diagonal(x, 1)\n",
    "    \n",
    "    corrnet = x\n",
    "\n",
    "    return corrnet \n",
    "  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Single Pearson Correlation Coefficient\n",
    "def spcc(data, i):\n",
    "    # Construct sample specific network\n",
    "    \n",
    "    mean_all = np.mean(data, axis=1)\n",
    "    sd_all = np.std(data, axis=1)\n",
    "    v = data[:, i]\n",
    "    x = (v - mean_all) / sd_all\n",
    "    x[np.isnan(x)] = 0\n",
    "    x[np.abs(x) == np.inf] = 0\n",
    "    prod = np.outer(x, x)\n",
    "    x = prod\n",
    "    m_x = np.max(np.abs(x[x != 0]))\n",
    "    x = x/m_x\n",
    "    np.fill_diagonal(x, 1)\n",
    "    \n",
    "    return x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the SPCC network\n",
    "def get_single_spcc_network(data, sample):\n",
    "    \"\"\"Compute single sample SPCC network\n",
    "\n",
    "    Args:\n",
    "        data (pd.DataFrame): expression dataframe, samples as columns and genes as rows\n",
    "        sample (str): sample name\n",
    "    \"\"\"\n",
    "    # Get the index of the sample\n",
    "    i = data.columns.tolist().index(sample)\n",
    "    # Get the network    \n",
    "    spcc_net = spcc(data.values, i)\n",
    "    # Put in dataframe\n",
    "    temp = pd.DataFrame(spcc_net, index = data.index, columns = data.index)\n",
    "    # Upper triangular matrix\n",
    "    temp = temp.where(np.triu(np.ones(temp.shape), k = 1).astype(bool))\n",
    "    # Put in long format\n",
    "    temp = temp.stack().reset_index() \n",
    "    # Rename columns\n",
    "    temp.columns = ['gene1','gene2',sample]\n",
    "    return(temp)\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_long_network(adj, columns = ['gene1','gene2', 'condition']):\n",
    "    \"\"\"Get long adjacency list from adjacency matrix\n",
    "\n",
    "    Args:\n",
    "        adj (pd.DataFrame): Adjacency matrix as dataframe (square)\n",
    "        columns (list, optional): name of the networks columns. Defaults to ['gene1','gene2', 'condition'].\n",
    "    \"\"\"\n",
    "    adj.index = adj.columns\n",
    "    df_long = adj.where(np.triu(np.ones(adj.shape), k = 1).astype(bool))\n",
    "    df_long = df_long.stack().reset_index() \n",
    "    df_long.columns = columns\n",
    "    return(df_long)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# For all of them we used:\n",
    "yeast_expression = 'data/inferelator/GSE125162_all_pseudobulk_logcounts.txt'\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SPCC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Read data\n",
    "with open(yeast_expression, 'r') as f:\n",
    "    df = pd.read_csv(f, sep='\\t', index_col=0)\n",
    "    df.index.name = None\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We need to select the sample names divided by media and genetics. \n",
    "This way we are gonna save only the networks based on the genetic background\n",
    "In total we are saving 11 files, instead of 132\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "ddd = pd.DataFrame()\n",
    "ddd['samples'] = df.columns\n",
    "ddd['media'] = ddd['samples'].str.split('_').str[1]\n",
    "ddd['genetic'] = ddd['samples'].str.split('_').str[0]\n",
    "\n",
    "if os.path.exists('../data/networks/spcc/'):\n",
    "    pass\n",
    "else:\n",
    "    os.makedirs('../data/networks/spcc/')\n",
    "\n",
    "for i,g in ddd.groupby('genetic'):\n",
    "    for k,sample in enumerate(g.samples.tolist()):\n",
    "        if k==0:\n",
    "            spcc_net = get_single_spcc_network(df, sample)\n",
    "        else:\n",
    "            temp = get_single_spcc_network(df, sample)\n",
    "            spcc_net = pd.concat([spcc_net, temp.iloc[:,2]], axis = 1)\n",
    "        if k==len(g.samples.tolist())-1:\n",
    "            spcc_net.to_hdf('../data/networks/inferelator_spcc_'+i+'.h5', key = 'spcc')\n",
    "            print('../data/networks/inferelator_spcc_'+i+'.h5')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Get the top 1k edges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import glob as glob\n",
    "ns = []\n",
    "for i,fn in enumerate(glob.glob('spcc/networks/inferelator_spcc_*.h5')):\n",
    "    print(i, fn)\n",
    "    df = pd.read_hdf(fn, key = 'spcc')\n",
    "    ns.append(len(df.columns)-2)\n",
    "    if i==0:\n",
    "        mysum = df.iloc[:,2:].sum(axis = 1)\n",
    "    else:\n",
    "        mysum += df.iloc[:,2:].sum(axis = 1)\n",
    "\n",
    "# Get top 1k edges\n",
    "mean = pd.Series(mysum/np.sum(ns))\n",
    "mean.sort_values(ascending = False, inplace = True)\n",
    "# Get top 1K\n",
    "top_1k = np.r_[mean.index.values[:500], mean.index.values[-500:]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now we re-read the networks and keep only the top1k edges"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i,fn in enumerate(glob.glob('spcc/networks/inferelator_spcc_*.h5')):\n",
    "    print(i, fn)\n",
    "    df = pd.read_hdf(fn, key = 'spcc')\n",
    "    if i==0:\n",
    "        spcc_net = df.iloc[top_1k, :]\n",
    "    else:\n",
    "        spcc_net = pd.concat([spcc_net, df.iloc[top_1k, 2:]], axis = 1)\n",
    "\n",
    "spcc_net.to_csv('spcc/networks/inferelator_spcc_top1k.csv', index = False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## SWEET\n",
    "\n",
    "To compute SWEET networks we are using the github code at [SysMednet/SWEET](https://github.com/SysMednet/SWEET).\n",
    "\n",
    "From there we cloned `1.SWEET_sample_weight_calculating.py` and `2.SWEET_edge_score_calculating.py` inside the src/sweet\n",
    "folder and run the inference as explained by the authors. \n",
    "\n",
    "However, since the zscore computation was extremely computationally heavy, we rewrote the code to make it more\n",
    "efficient. Note that we are not changing any inference step, but only making the reading/saving/storing steps \n",
    "more efficient.\n",
    "\n",
    "#### Create patient and gene files"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "patient = '../data/processed_data/sweet_patient.txt'\n",
    "gene = '../data/processed_data/sweet_gene.txt'\n",
    "\n",
    "ppp = df.columns[1:].tolist()\n",
    "pd.DataFrame(ppp).to_csv(patient, index = False, header = False, sep = '\\t')\n",
    "\n",
    "ggg = df.Gene.tolist()\n",
    "pd.DataFrame(ggg).to_csv(gene, index = False, header = False, sep = '\\t')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Compute the weights\n",
    "These steps can be done outside of this notebook. \n",
    "\n",
    "```bash\n",
    "python3 ../src/sweet/1.SWEET_sample_weight_calculating.py -f '../data/processed_data/GSE125162_all_pseudobulk_logcounts.txt' -s ../data/networks/sweet/GSE125162_all_pseudobulk_logcounts_weight.txt\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Network inference\n",
    "\n",
    "``` bash\n",
    "python3 ../src/sweet/2.SWEET_edge_score_calculating.py -f '../data/processed_data/GSE125162_all_pseudobulk_logcounts.txt' \\\n",
    "    -w '../data/networks/sweet/GSE125162_all_pseudobulk_logcounts_weight.txt' \\\n",
    "        -p '../data/processed_data/sweet_patient.txt' \\\n",
    "        -g '../data/processed_data/sweet_gene.txt' \\\n",
    "        -s '../data/networks/sweet/'\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Get top1k network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# compute mean and std of all networks accessing each network separately\n",
    "def compose_std(x, m):\n",
    "    return(np.sum((x - m)**2))\n",
    "    \n",
    "\n",
    "def compute_composed_mean_and_std(nets_filename_list):\n",
    "    means = []\n",
    "    sss = []\n",
    "    ns = []\n",
    "\n",
    "    for i,net in enumerate(nets_filename_list):\n",
    "        with open(net,'r') as f:\n",
    "            net = pd.read_csv(f, sep = '\\t')\n",
    "        net['raw_edge_score'] = net['raw_edge_score'].astype(float)\n",
    "        ns.append(len(net))\n",
    "        means.append(net['raw_edge_score'].mean())\n",
    "        #stds.append(net['raw_edge_score'].std())\n",
    "    \n",
    "    means = np.array(means)\n",
    "    ns = np.array(ns)\n",
    "    mean = np.sum(means*ns)/np.sum(ns)\n",
    "    \n",
    "    for i,net in enumerate(nets_filename_list):\n",
    "        with open(net,'r') as f:\n",
    "            net = pd.read_csv(f, sep = '\\t')\n",
    "        net['raw_edge_score'] = net['raw_edge_score'].astype(float)\n",
    "        sss.append(compose_std(net['raw_edge_score'].values, mean))\n",
    "    sss = np.array(sss)\n",
    "        \n",
    "    std2 = np.sqrt(np.sum(sss)/np.sum(ns))\n",
    "    \n",
    "    \n",
    "    \n",
    "    return mean, std2\n",
    "\n",
    "\n",
    "def compute_rowise_mean(nets_filename_list, verbose = 5):\n",
    "    means = []\n",
    "    ns = []\n",
    "\n",
    "    for i,net in enumerate(nets_filename_list):\n",
    "        if (i%verbose==0):\n",
    "            print('Reading network %d' %i)\n",
    "        with open(net,'r') as f:\n",
    "            net = pd.read_csv(f, sep = '\\t')\n",
    "        if i==0:\n",
    "            edges = np.zeros(len(net))\n",
    "        edges += net['raw_edge_score'].astype(float)\n",
    "\n",
    "    \n",
    "    edges = edges/len(nets_filename_list)\n",
    "    mean_net = pd.DataFrame({'gene1':net['gene1'], 'gene2':net['gene2'], 'mean_edge':edges})\n",
    "    return(mean_net)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get the top1k \n",
    "mean_net = compute_rowise_mean(nets_fn, verbose = 10)\n",
    "mean_net = mean_net.sort_values(by = ['mean_edge'], ascending = False)\n",
    "# Save the mean network\n",
    "mean_net.to_csv('../data/networks/sweet/mean_network.txt', sep = '\\t', index = False)\n",
    "\n",
    "mean_net_top1k = mean_net.loc[np.r_[mean_net.index.tolist()[:500],mean_net.index.tolist()[-500:]],:]\n",
    "mean_net_top1k"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for i,netfn in enumerate(nets_fn):\n",
    "    if (i%10)==0:\n",
    "        print('Reading network %d' %i)\n",
    "    with open(netfn,'r') as f:\n",
    "        net = pd.read_csv(f, sep = '\\t')\n",
    "        net_name = netfn.split('/')[-1].split('.')[0]\n",
    "        net.columns = ['gene1','gene2',net_name]\n",
    "    if i==0:\n",
    "        net_top1k = net.iloc[mean_net_top1k.index.tolist(),:]\n",
    "    else:\n",
    "        net_top1k = pd.concat([net_top1k, net.iloc[mean_net_top1k.index.tolist(),2]], axis = 1)\n",
    "\n",
    "# Save top1k network\n",
    "net_top1k.to_csv('../data/networks/GSE125162_all_pseudobulk_logcounts_sweet_networks_top1k.txt', sep = '\\t', index = False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Get the sparse network"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Here is the code to compute the mean and std of the composed network\n",
    "# This is quite slow, so I will not run it now\n",
    "nets_fn = glob.glob('spcc/networks/inferelator_spcc_*.h5')\n",
    "if False:\n",
    "    m,s= compute_composed_mean_and_std(nets_fn)\n",
    "\n",
    "# m, s\n",
    "#mean: 0.2204959613090935, std: 0.2430662602336294"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "all_mean = 0.2204959613090935\n",
    "all_std = 0.2430662602336294"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_sparse_net(net_filename, mean, std, p_th = 0.01):\n",
    "        with open(net_filename,'r') as f:\n",
    "            net = pd.read_csv(f, sep = '\\t')\n",
    "        net['raw_edge_score'] = net['raw_edge_score'].astype(float)\n",
    "        net['zscores'] = (net['raw_edge_score'] - mean)/std\n",
    "        zth = stats.norm.isf(p_th/2)\n",
    "        net = net[net['zscores'].abs()>zth]\n",
    "        return(net.iloc[:,:3])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "sparse_sweet = get_sparse_net(nets_fn[0], all_mean, all_std, p_th = 0.01)\n",
    "sparse_sweet.columns = ['gene1','gene2',nets_fn[0].split('/')[-1][:-4]]\n",
    "\n",
    "for i, net_filename in enumerate(nets_fn[1:]):\n",
    "    if i%5==0:\n",
    "        print('Processing network %d' % i)\n",
    "    net = get_sparse_net(net_filename, all_mean, all_std, p_th = 0.01)\n",
    "    net.columns = ['gene1','gene2',net_filename.split('/')[-1][:-4]]\n",
    "    sparse_sweet = pd.merge(sparse_sweet, net, how = 'outer', on = ['gene1','gene2'])\n",
    "sparse_sweet\n",
    "sparse_sweet.to_csv('../data/networks/GSE125162_all_pseudobulk_logcounts_sweet_networks_sparse.txt', index = False, sep = '\\t')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## LIONESS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "def get_lioness_dataframe(nets_fn):\n",
    "\n",
    "    df_lioness = pd.DataFrame()\n",
    "\n",
    "    for iii,bbb in enumerate(nets_fn):\n",
    "        print(bbb)\n",
    "        if iii>-1:\n",
    "            k = bbb.split('/')[-1][:-3][8:]\n",
    "            temp = pd.read_hdf(bbb, key = 'lioness')\n",
    "                \n",
    "            temp.index = temp.columns\n",
    "            # Upper triangular matrix\n",
    "            temp = temp.where(np.triu(np.ones(temp.shape), k = 1).astype(bool))\n",
    "            # Put in long format\n",
    "            temp = temp.stack().reset_index() \n",
    "            # Rename columns\n",
    "            temp.columns = ['gene1','gene2',k]\n",
    "            \n",
    "            if iii == 0:\n",
    "                df_lioness = temp\n",
    "            else:\n",
    "                df_lioness[k] = temp[k]\n",
    "            \n",
    "\n",
    "    return(df_lioness)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Compute the networks"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>WT(ho)_AmmoniumSulfate</th>\n",
       "      <th>WT(ho)_CStarve</th>\n",
       "      <th>WT(ho)_Glutamine</th>\n",
       "      <th>WT(ho)_MinimalEtOH</th>\n",
       "      <th>WT(ho)_MinimalGlucose</th>\n",
       "      <th>WT(ho)_Proline</th>\n",
       "      <th>WT(ho)_Urea</th>\n",
       "      <th>WT(ho)_YPD</th>\n",
       "      <th>WT(ho)_YPDDiauxic</th>\n",
       "      <th>WT(ho)_YPDRapa</th>\n",
       "      <th>...</th>\n",
       "      <th>stp2_CStarve</th>\n",
       "      <th>stp2_Glutamine</th>\n",
       "      <th>stp2_MinimalEtOH</th>\n",
       "      <th>stp2_MinimalGlucose</th>\n",
       "      <th>stp2_Proline</th>\n",
       "      <th>stp2_Urea</th>\n",
       "      <th>stp2_YPD</th>\n",
       "      <th>stp2_YPDDiauxic</th>\n",
       "      <th>stp2_YPDRapa</th>\n",
       "      <th>stp2_YPEtOH</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Gene</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>YDL248W</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.004890</td>\n",
       "      <td>0.015267</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.003180</td>\n",
       "      <td>0.002144</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.004040</td>\n",
       "      <td>0.009852</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.006494</td>\n",
       "      <td>0.003743</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>YDL247W</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>YDL246C</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>YDL245C</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.004175</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.002144</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.017700</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.001249</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>YDL244W</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.012474</td>\n",
       "      <td>0.006734</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.006780</td>\n",
       "      <td>0.001024</td>\n",
       "      <td>0.028259</td>\n",
       "      <td>0.022282</td>\n",
       "      <td>...</td>\n",
       "      <td>0.017778</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.035091</td>\n",
       "      <td>0.012073</td>\n",
       "      <td>0.009852</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.001278</td>\n",
       "      <td>0.012945</td>\n",
       "      <td>0.024693</td>\n",
       "      <td>0.061875</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q0255</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Q0275</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.004890</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.003180</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.006494</td>\n",
       "      <td>0.001249</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>RPM1</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KANMX</th>\n",
       "      <td>2.360386</td>\n",
       "      <td>1.014260</td>\n",
       "      <td>2.011293</td>\n",
       "      <td>1.759183</td>\n",
       "      <td>2.200487</td>\n",
       "      <td>1.268030</td>\n",
       "      <td>2.427748</td>\n",
       "      <td>1.901312</td>\n",
       "      <td>1.486226</td>\n",
       "      <td>1.456467</td>\n",
       "      <td>...</td>\n",
       "      <td>1.001357</td>\n",
       "      <td>2.033365</td>\n",
       "      <td>2.207096</td>\n",
       "      <td>2.372927</td>\n",
       "      <td>1.500772</td>\n",
       "      <td>2.615808</td>\n",
       "      <td>1.996838</td>\n",
       "      <td>1.457781</td>\n",
       "      <td>1.563132</td>\n",
       "      <td>2.406881</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>NATMX</th>\n",
       "      <td>2.588820</td>\n",
       "      <td>1.358721</td>\n",
       "      <td>2.786845</td>\n",
       "      <td>1.978345</td>\n",
       "      <td>2.986127</td>\n",
       "      <td>1.757858</td>\n",
       "      <td>2.659736</td>\n",
       "      <td>3.098374</td>\n",
       "      <td>1.951807</td>\n",
       "      <td>2.841197</td>\n",
       "      <td>...</td>\n",
       "      <td>1.343930</td>\n",
       "      <td>2.772589</td>\n",
       "      <td>2.268068</td>\n",
       "      <td>3.187456</td>\n",
       "      <td>1.753067</td>\n",
       "      <td>2.841871</td>\n",
       "      <td>3.260749</td>\n",
       "      <td>2.014251</td>\n",
       "      <td>3.067180</td>\n",
       "      <td>3.015396</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>6520 rows × 132 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         WT(ho)_AmmoniumSulfate  WT(ho)_CStarve  WT(ho)_Glutamine  \\\n",
       "Gene                                                                \n",
       "YDL248W                0.000000        0.000000          0.000000   \n",
       "YDL247W                0.000000        0.000000          0.000000   \n",
       "YDL246C                0.000000        0.000000          0.000000   \n",
       "YDL245C                0.000000        0.004175          0.000000   \n",
       "YDL244W                0.000000        0.012474          0.006734   \n",
       "...                         ...             ...               ...   \n",
       "Q0255                  0.000000        0.000000          0.000000   \n",
       "Q0275                  0.000000        0.000000          0.000000   \n",
       "RPM1                   0.000000        0.000000          0.000000   \n",
       "KANMX                  2.360386        1.014260          2.011293   \n",
       "NATMX                  2.588820        1.358721          2.786845   \n",
       "\n",
       "         WT(ho)_MinimalEtOH  WT(ho)_MinimalGlucose  WT(ho)_Proline  \\\n",
       "Gene                                                                 \n",
       "YDL248W            0.000000               0.004890        0.015267   \n",
       "YDL247W            0.000000               0.000000        0.000000   \n",
       "YDL246C            0.000000               0.000000        0.000000   \n",
       "YDL245C            0.000000               0.000000        0.000000   \n",
       "YDL244W            0.000000               0.000000        0.000000   \n",
       "...                     ...                    ...             ...   \n",
       "Q0255              0.000000               0.000000        0.000000   \n",
       "Q0275              0.000000               0.004890        0.000000   \n",
       "RPM1               0.000000               0.000000        0.000000   \n",
       "KANMX              1.759183               2.200487        1.268030   \n",
       "NATMX              1.978345               2.986127        1.757858   \n",
       "\n",
       "         WT(ho)_Urea  WT(ho)_YPD  WT(ho)_YPDDiauxic  WT(ho)_YPDRapa  ...  \\\n",
       "Gene                                                                 ...   \n",
       "YDL248W     0.000000    0.000000           0.003180        0.002144  ...   \n",
       "YDL247W     0.000000    0.000000           0.000000        0.000000  ...   \n",
       "YDL246C     0.000000    0.000000           0.000000        0.000000  ...   \n",
       "YDL245C     0.000000    0.000000           0.000000        0.002144  ...   \n",
       "YDL244W     0.006780    0.001024           0.028259        0.022282  ...   \n",
       "...              ...         ...                ...             ...  ...   \n",
       "Q0255       0.000000    0.000000           0.000000        0.000000  ...   \n",
       "Q0275       0.000000    0.000000           0.003180        0.000000  ...   \n",
       "RPM1        0.000000    0.000000           0.000000        0.000000  ...   \n",
       "KANMX       2.427748    1.901312           1.486226        1.456467  ...   \n",
       "NATMX       2.659736    3.098374           1.951807        2.841197  ...   \n",
       "\n",
       "         stp2_CStarve  stp2_Glutamine  stp2_MinimalEtOH  stp2_MinimalGlucose  \\\n",
       "Gene                                                                           \n",
       "YDL248W      0.000000        0.000000          0.000000             0.004040   \n",
       "YDL247W      0.000000        0.000000          0.000000             0.000000   \n",
       "YDL246C      0.000000        0.000000          0.000000             0.000000   \n",
       "YDL245C      0.000000        0.000000          0.017700             0.000000   \n",
       "YDL244W      0.017778        0.000000          0.035091             0.012073   \n",
       "...               ...             ...               ...                  ...   \n",
       "Q0255        0.000000        0.000000          0.000000             0.000000   \n",
       "Q0275        0.000000        0.000000          0.000000             0.000000   \n",
       "RPM1         0.000000        0.000000          0.000000             0.000000   \n",
       "KANMX        1.001357        2.033365          2.207096             2.372927   \n",
       "NATMX        1.343930        2.772589          2.268068             3.187456   \n",
       "\n",
       "         stp2_Proline  stp2_Urea  stp2_YPD  stp2_YPDDiauxic  stp2_YPDRapa  \\\n",
       "Gene                                                                        \n",
       "YDL248W      0.009852   0.000000  0.000000         0.006494      0.003743   \n",
       "YDL247W      0.000000   0.000000  0.000000         0.000000      0.000000   \n",
       "YDL246C      0.000000   0.000000  0.000000         0.000000      0.000000   \n",
       "YDL245C      0.000000   0.000000  0.000000         0.000000      0.001249   \n",
       "YDL244W      0.009852   0.000000  0.001278         0.012945      0.024693   \n",
       "...               ...        ...       ...              ...           ...   \n",
       "Q0255        0.000000   0.000000  0.000000         0.000000      0.000000   \n",
       "Q0275        0.000000   0.000000  0.000000         0.006494      0.001249   \n",
       "RPM1         0.000000   0.000000  0.000000         0.000000      0.000000   \n",
       "KANMX        1.500772   2.615808  1.996838         1.457781      1.563132   \n",
       "NATMX        1.753067   2.841871  3.260749         2.014251      3.067180   \n",
       "\n",
       "         stp2_YPEtOH  \n",
       "Gene                  \n",
       "YDL248W     0.000000  \n",
       "YDL247W     0.000000  \n",
       "YDL246C     0.000000  \n",
       "YDL245C     0.000000  \n",
       "YDL244W     0.061875  \n",
       "...              ...  \n",
       "Q0255       0.000000  \n",
       "Q0275       0.000000  \n",
       "RPM1        0.000000  \n",
       "KANMX       2.406881  \n",
       "NATMX       3.015396  \n",
       "\n",
       "[6520 rows x 132 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we need the logcounts\n",
    "df = pd.read_csv(yeast_expression, sep = '\\t', index_col = 0)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/ubuntu/miniconda3/envs/nb/lib/python3.9/site-packages/numpy/lib/function_base.py:2897: RuntimeWarning: invalid value encountered in divide\n",
      "  c /= stddev[:, None]\n",
      "/home/ubuntu/miniconda3/envs/nb/lib/python3.9/site-packages/numpy/lib/function_base.py:2898: RuntimeWarning: invalid value encountered in divide\n",
      "  c /= stddev[None, :]\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "87\n"
     ]
    }
   ],
   "source": [
    "# Compute the lioness networks\n",
    "for i range(len(df.columns)):\n",
    "    temp = pd.DataFrame(data = lioness(df, df.columns[i]), columns = df.index)\n",
    "    temp.index.name = None\n",
    "    temp.columns.name = None\n",
    "    temp.to_hdf('data/networks/lioness_%s.h5' %df.columns[i], key = 'lioness')\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Re-read the networks and prepare the top1k net"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'glob' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m netsfn \u001b[38;5;241m=\u001b[39m \u001b[43mglob\u001b[49m\u001b[38;5;241m.\u001b[39mglob(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../../bonobo_data/lioness/*\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m      2\u001b[0m df_lioness \u001b[38;5;241m=\u001b[39m get_lioness_dataframe(netsfn)\n",
      "\u001b[0;31mNameError\u001b[0m: name 'glob' is not defined"
     ]
    }
   ],
   "source": [
    "netsfn = glob.glob('../../bonobo_data/lioness/*')\n",
    "df_lioness = get_lioness_dataframe(netsfn)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>gene1</th>\n",
       "      <th>gene2</th>\n",
       "      <th>stp1_CStarve</th>\n",
       "      <th>rtg3_MinimalEtOH</th>\n",
       "      <th>gzf3_YPEtOH</th>\n",
       "      <th>gcn4_AmmoniumSulfate</th>\n",
       "      <th>dal81_MinimalEtOH</th>\n",
       "      <th>stp1_YPEtOH</th>\n",
       "      <th>rtg3_MinimalGlucose</th>\n",
       "      <th>rtg1_YPDRapa</th>\n",
       "      <th>...</th>\n",
       "      <th>stp2_YPD</th>\n",
       "      <th>dal81_Glutamine</th>\n",
       "      <th>rtg1_Urea</th>\n",
       "      <th>stp1_Glutamine</th>\n",
       "      <th>WT(ho)_MinimalGlucose</th>\n",
       "      <th>dal80_Urea</th>\n",
       "      <th>rtg1_MinimalGlucose</th>\n",
       "      <th>dal80_YPEtOH</th>\n",
       "      <th>dal82_MinimalGlucose</th>\n",
       "      <th>rtg3_AmmoniumSulfate</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>YDL248W</td>\n",
       "      <td>YDL247W</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>-0.386530</td>\n",
       "      <td>-0.234333</td>\n",
       "      <td>-0.386530</td>\n",
       "      <td>-0.023281</td>\n",
       "      <td>...</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>-0.034989</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>-0.034989</td>\n",
       "      <td>-0.031320</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>-0.065201</td>\n",
       "      <td>0.059980</td>\n",
       "      <td>0.059980</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>YDL248W</td>\n",
       "      <td>YDL246C</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>-0.086056</td>\n",
       "      <td>-0.147757</td>\n",
       "      <td>-0.086056</td>\n",
       "      <td>-0.064493</td>\n",
       "      <td>...</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>-0.073943</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>-0.073943</td>\n",
       "      <td>-0.071040</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>-0.095810</td>\n",
       "      <td>0.017953</td>\n",
       "      <td>0.017953</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>YDL248W</td>\n",
       "      <td>YDL245C</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>-0.194102</td>\n",
       "      <td>-0.258938</td>\n",
       "      <td>-0.194102</td>\n",
       "      <td>0.142542</td>\n",
       "      <td>...</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>-0.114954</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>-0.114954</td>\n",
       "      <td>-0.110017</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>-0.152585</td>\n",
       "      <td>0.037624</td>\n",
       "      <td>0.037624</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>YDL248W</td>\n",
       "      <td>YDL244W</td>\n",
       "      <td>-0.326455</td>\n",
       "      <td>-0.183065</td>\n",
       "      <td>-1.454582</td>\n",
       "      <td>0.556953</td>\n",
       "      <td>21.848356</td>\n",
       "      <td>2.974861</td>\n",
       "      <td>-4.088434</td>\n",
       "      <td>0.118830</td>\n",
       "      <td>...</td>\n",
       "      <td>0.521763</td>\n",
       "      <td>-0.034138</td>\n",
       "      <td>0.556953</td>\n",
       "      <td>-0.154630</td>\n",
       "      <td>-0.124578</td>\n",
       "      <td>0.556953</td>\n",
       "      <td>0.556953</td>\n",
       "      <td>0.690581</td>\n",
       "      <td>0.556953</td>\n",
       "      <td>0.556953</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>YDL248W</td>\n",
       "      <td>YDL243C</td>\n",
       "      <td>0.309936</td>\n",
       "      <td>-0.465772</td>\n",
       "      <td>-0.281539</td>\n",
       "      <td>0.712555</td>\n",
       "      <td>-0.447760</td>\n",
       "      <td>0.121222</td>\n",
       "      <td>-4.644132</td>\n",
       "      <td>0.252321</td>\n",
       "      <td>...</td>\n",
       "      <td>0.438039</td>\n",
       "      <td>-0.185021</td>\n",
       "      <td>0.712555</td>\n",
       "      <td>-0.150324</td>\n",
       "      <td>-0.229136</td>\n",
       "      <td>0.515937</td>\n",
       "      <td>0.712555</td>\n",
       "      <td>0.516237</td>\n",
       "      <td>0.384148</td>\n",
       "      <td>-0.179146</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 134 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     gene1    gene2  stp1_CStarve  rtg3_MinimalEtOH  gzf3_YPEtOH  \\\n",
       "0  YDL248W  YDL247W      0.059980          0.059980     0.059980   \n",
       "1  YDL248W  YDL246C      0.017953          0.017953     0.017953   \n",
       "2  YDL248W  YDL245C      0.037624          0.037624     0.037624   \n",
       "3  YDL248W  YDL244W     -0.326455         -0.183065    -1.454582   \n",
       "4  YDL248W  YDL243C      0.309936         -0.465772    -0.281539   \n",
       "\n",
       "   gcn4_AmmoniumSulfate  dal81_MinimalEtOH  stp1_YPEtOH  rtg3_MinimalGlucose  \\\n",
       "0              0.059980          -0.386530    -0.234333            -0.386530   \n",
       "1              0.017953          -0.086056    -0.147757            -0.086056   \n",
       "2              0.037624          -0.194102    -0.258938            -0.194102   \n",
       "3              0.556953          21.848356     2.974861            -4.088434   \n",
       "4              0.712555          -0.447760     0.121222            -4.644132   \n",
       "\n",
       "   rtg1_YPDRapa  ...  stp2_YPD  dal81_Glutamine  rtg1_Urea  stp1_Glutamine  \\\n",
       "0     -0.023281  ...  0.059980        -0.034989   0.059980       -0.034989   \n",
       "1     -0.064493  ...  0.017953        -0.073943   0.017953       -0.073943   \n",
       "2      0.142542  ...  0.037624        -0.114954   0.037624       -0.114954   \n",
       "3      0.118830  ...  0.521763        -0.034138   0.556953       -0.154630   \n",
       "4      0.252321  ...  0.438039        -0.185021   0.712555       -0.150324   \n",
       "\n",
       "   WT(ho)_MinimalGlucose  dal80_Urea  rtg1_MinimalGlucose  dal80_YPEtOH  \\\n",
       "0              -0.031320    0.059980             0.059980     -0.065201   \n",
       "1              -0.071040    0.017953             0.017953     -0.095810   \n",
       "2              -0.110017    0.037624             0.037624     -0.152585   \n",
       "3              -0.124578    0.556953             0.556953      0.690581   \n",
       "4              -0.229136    0.515937             0.712555      0.516237   \n",
       "\n",
       "   dal82_MinimalGlucose  rtg3_AmmoniumSulfate  \n",
       "0              0.059980              0.059980  \n",
       "1              0.017953              0.017953  \n",
       "2              0.037624              0.037624  \n",
       "3              0.556953              0.556953  \n",
       "4              0.384148             -0.179146  \n",
       "\n",
       "[5 rows x 134 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_lioness.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "df_all = df_lioness\n",
    "\n",
    "# Get top 1k edges\n",
    "mean = df_all.iloc[:,2:].mean(axis = 1)\n",
    "mean.sort_values(ascending = False, inplace = True)\n",
    "# Get top 1K\n",
    "top_1k = np.r_[mean.index.values[:500], mean.index.values[-500:]]\n",
    "df_top1k = df_all.iloc[top_1k, :]\n",
    "#df_top1k\n",
    "df_top1k.to_csv('../data/networks/lioness_top1k.csv', index = False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "nb",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
